package com.wangjiyuan.giftshuo.ui.activity.classify.shop_details.recycler_adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.shop.ShopDetLayoutBean;
import com.wangjiyuan.giftshuo.utils.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * Created by QXL on 2016/11/24.
 */

public class ShopDetLayoutRecyclerAdapter extends RecyclerViewAdapterHelper<ShopDetLayoutBean.DataBean.ItemsBean> {
    private int widthPixels;
    private int heightPixels;

    public ShopDetLayoutRecyclerAdapter(Context context, List<ShopDetLayoutBean.DataBean.ItemsBean> list) {
        super(context, list);
        widthPixels = mContext.getResources().getDisplayMetrics().widthPixels;
        heightPixels = mContext.getResources().getDisplayMetrics().heightPixels;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_shopdet_layout, parent, false);
        return new ViewHolderShopDet(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        ShopDetLayoutBean.DataBean.ItemsBean itemsBean = mList.get(position);
        String coverImageUrl = itemsBean.getCoverImageUrl();
        String name = itemsBean.getName();
        String price = itemsBean.getPrice();
        Glide.with(mContext).load(coverImageUrl)
                .placeholder(R.mipmap.white)
                .override(widthPixels/2-10*2,heightPixels/5)
                .centerCrop()
                .into(((ViewHolderShopDet)holder).imageView_item_ShopDetLayout);
        ((ViewHolderShopDet) holder).textView_ShopDetLayout_name.setText(name);
        ((ViewHolderShopDet) holder).textView_ShopDetLayout_money.setText("￥ "+price);
    }

    class ViewHolderShopDet extends RecyclerView.ViewHolder {
        RelativeLayout linearLayout_ShopDetLayout;
        ImageView imageView_item_ShopDetLayout;
        TextView textView_ShopDetLayout_name,textView_ShopDetLayout_money;
        public ViewHolderShopDet(View itemView) {
            super(itemView);
            RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(widthPixels/2-10*2,heightPixels/3);
            linearLayout_ShopDetLayout= (RelativeLayout) itemView.findViewById(R.id.linearLayout_ShopDetLayout);
            linearLayout_ShopDetLayout.setLayoutParams(layoutParams);
            layoutParams.setMargins(10,10,0,0);

            imageView_item_ShopDetLayout= (ImageView) itemView.findViewById(R.id.imageView_item_ShopDetLayout);
            textView_ShopDetLayout_name= (TextView) itemView.findViewById(R.id.textView_ShopDetLayout_name);
            textView_ShopDetLayout_name.setPadding(10,25,0,0);
            textView_ShopDetLayout_money= (TextView) itemView.findViewById(R.id.textView_ShopDetLayout_money);
            textView_ShopDetLayout_money.setPadding(10,0,0,10);
        }
    }
}
